package nexus.com.date
{
	import flash.events.MouseEvent;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFormat;
	
	import nexus.base.NXSprite;
	import nexus.com.date.DateVO;
	
	
	
	/**
	 * <br>설명 : </br> 
	 * @author winnie
	 */	
	public class DateItem extends NXSprite
	{
		//-----------------------------------------------------------------------------------
		//
		// private vars
		//
		//-----------------------------------------------------------------------------------
		private var _vo : DateVO;
		private var _isCurrentDate : Boolean = false;
		private var _textField : TextField;
		private var _currentTextFormat : TextFormat;
		private var _onTextFormat : TextFormat;
		private var _offTextFormat : TextFormat;
		
		//-----------------------------------------------------------------------------------
		//
		// protected vars
		//
		//-----------------------------------------------------------------------------------
		
		
		//-----------------------------------------------------------------------------------
		//
		// public vars
		//
		//-----------------------------------------------------------------------------------
		
		
		
		//-----------------------------------------------------------------------------------
		//
		// constructor
		//
		//-----------------------------------------------------------------------------------
		public function DateItem()
		{
			super();
			
			this.buttonMode = true;
		}
		
		
		//-----------------------------------------------------------------------------------
		//
		// setter / getter
		//
		//-----------------------------------------------------------------------------------

		public function get vo():DateVO
		{
			return _vo;
		}

		public function set vo(value:DateVO):void
		{
			_vo = value;
			textField.text = String( _vo.date );
			textField.width = textField.textWidth+4;
		}
		
		public function get currentTextFormat():TextFormat
		{
			if( _currentTextFormat == null )
			{
				_currentTextFormat = new TextFormat( "돋움", 12, 0x868686, false );
			}
			
			return _currentTextFormat;
		}
		
		public function set currentTextFormat(value:TextFormat):void
		{
			_currentTextFormat = value;
		}
		
		public function get offTextFormat():TextFormat
		{
			if( _offTextFormat == null )
			{
				_offTextFormat = new TextFormat( "돋움", 12, 0x868686, false );
			}
			
			return _offTextFormat;
		}

		public function set offTextFormat(value:TextFormat):void
		{
			_offTextFormat = value;
		}

		public function get onTextFormat():TextFormat
		{
			if( _onTextFormat == null )
			{
				_onTextFormat = new TextFormat( "돋움", 12, 0xcb1a1b, true );
			}
			return _onTextFormat;
		}

		public function set onTextFormat(value:TextFormat):void
		{
			_onTextFormat = value;
		}

		public function get textField():TextField
		{
			if( _textField == null )
			{
				_textField = new TextField();
				_textField.autoSize = TextFieldAutoSize.LEFT;
				_textField.mouseEnabled = false;
				_textField.mouseWheelEnabled = false;
				
				_textField.setTextFormat( offTextFormat );
				_textField.defaultTextFormat = offTextFormat;
				
				addChild( _textField );
			}
			
			return _textField;
		}

		public function set textField(value:TextField):void
		{
			if( _textField != null )
			{
				if( this.contains( _textField ) )
				{
					removeChild( _textField );
				}
				
				_textField = null;
			}
			_textField = value;
		}

		public function get isCurrentDate():Boolean
		{
			return _isCurrentDate;
		}
		
		public function set isCurrentDate(value:Boolean):void
		{
			_isCurrentDate = value;
			
			
			textField.setTextFormat( currentTextFormat );
		}
		
		
		//-----------------------------------------------------------------------------------
		//
		// public function
		//
		//-----------------------------------------------------------------------------------
		
		
		override public function updateDisplayList():void
		{
			super.updateDisplayList();
			
			textField.x = ( viewWidth-textField.width ) / 2;
			textField.y = ( viewHeight-textField.height ) / 2;
		}
		
		
		public function ON():void
		{
			textField.setTextFormat( onTextFormat );
		}
		
		public function OFF():void
		{
			textField.setTextFormat( (isCurrentDate) ? currentTextFormat : offTextFormat );
		}
		
		
		
		
		//-----------------------------------------------------------------------------------
		//
		// protected function
		//
		//-----------------------------------------------------------------------------------
		
		
		
		
		//-----------------------------------------------------------------------------------
		//
		// private function
		//
		//-----------------------------------------------------------------------------------
		
		
		
		//-----------------------------------------------------------------------------------
		//
		// event handler
		//
		//-----------------------------------------------------------------------------------
		
		
		
		//-----------------------------------------------------------------------------------
		//
		// destory
		//
		//-----------------------------------------------------------------------------------

		
		override public function destory():void
		{
			super.destory();
		}

	}
}